package com.aletto.general_store.ui.popup;

import android.content.Context;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.aletto.general_store.R;
import com.aletto.general_store.data.model.ConsumerOrder;
import com.aletto.general_store.data.model.Goods;
import com.aletto.general_store.ui.activities.orders.ConsumerOrderActivity;
import com.aletto.general_store.ui.activities.orders.OrderConsumerDeliveryActivity;
import com.aletto.general_store.utils.XHelper;
import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.util.XPopupUtils;

import androidx.annotation.NonNull;

import java.math.BigDecimal;

public class PaySuccessPopup extends CenterPopupView {

    private  int number;

    private Goods goods;

    public PaySuccessPopup(@NonNull Context context, Goods goods, int number) {
        super(context);
        this.goods = goods;
        this.number = number;
    }

    public PaySuccessPopup(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getMaxWidth() {
        if (this.popupInfo == null) {
            return 0;
        } else {
            return this.popupInfo.maxWidth == 0 ? (int) ((float) XPopupUtils.getAppWidth(this.getContext()) * 0.7F) : this.popupInfo.maxWidth;
        }
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.popup_pay_success;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        TextView tv_price = findViewById(R.id.tv_price);
        Button button_confirm = findViewById(R.id.button_confirm);
        TextView tv_order_details = findViewById(R.id.tv_order_details);

        BigDecimal price = new BigDecimal(Float.parseFloat(goods.getPrice()) * number);
        tv_price.setText(XHelper.toPrice(price) + " USDT");

        Context context = getContext();
        tv_order_details.setOnClickListener(v-> {
            dismiss();
            context.startActivity(ConsumerOrderActivity.newIntent(context, ConsumerOrder.delivery));
        });

        button_confirm.setOnClickListener(v -> dismiss());
        findViewById(R.id.iv_close).setOnClickListener(v -> dismiss());

    }
}
